package com.lehecai.ucenter.client;

import java.util.HashMap;
import java.util.Map;

import com.lehecai.core.util.CharsetConstant;
import com.lehecai.core.util.CoreHttpUtils;
import com.lehecai.ucenter.utils.AuthorizeSignUtils;

public class AppClient {
	private String baseUrl;
	private String appToken;
	private String appSecret;
	
	public String generateAuthorizeUrl(String callback) {
		String url = baseUrl + "/authorize.do";
		Map<String, String> params = new HashMap<String, String>();
		params.put("token", appToken);
		params.put("random", AuthorizeSignUtils.generateRandomParam());
		params.put("callback", callback);
		
		params.put("sign", AuthorizeSignUtils.generateAuthorizeSign(params, appSecret));
		return CoreHttpUtils.getQueryUrl(url, params, CharsetConstant.CHARSET_UTF8);
	}
	
	public String generateVerifyUrl(String uid, String ticket) {
		String url = baseUrl + "/verify.do";
		Map<String, String> params = new HashMap<String, String>();
		params.put("token", appToken);
		params.put("uid", uid);
		params.put("ticket", ticket);
		params.put("random", AuthorizeSignUtils.generateRandomParam());
		params.put("sign", AuthorizeSignUtils.generateAuthorizeSign(params, appSecret));
		return CoreHttpUtils.getQueryUrl(url, params, CharsetConstant.CHARSET_UTF8);
	}
	
	public String generateChangePwdUrl(String uid) {
		String url = baseUrl + "/changePwdAuthorize.do";
		Map<String, String> params = new HashMap<String, String>();
		params.put("token", appToken);
		params.put("uid", uid);
		params.put("random", AuthorizeSignUtils.generateRandomParam());
		params.put("sign", AuthorizeSignUtils.generateAuthorizeSign(params, appSecret));
		return CoreHttpUtils.getQueryUrl(url, params, CharsetConstant.CHARSET_UTF8);
	}
	
	public String generateChangeInfoUrl(String uid, String backUrl) {
		String url = baseUrl + "/changeInfoAuthorize.do";
		Map<String, String> params = new HashMap<String, String>();
		params.put("token", appToken);
		params.put("uid", uid);
		params.put("callback", backUrl);
		params.put("random", AuthorizeSignUtils.generateRandomParam());
		
		params.put("sign", AuthorizeSignUtils.generateAuthorizeSign(params, appSecret));
		return CoreHttpUtils.getQueryUrl(url, params, CharsetConstant.CHARSET_UTF8);
	}

	public String getBaseUrl() {
		return baseUrl;
	}

	public void setBaseUrl(String baseUrl) {
		this.baseUrl = baseUrl;
	}

	public String getAppToken() {
		return appToken;
	}

	public void setAppToken(String appToken) {
		this.appToken = appToken;
	}

	public String getAppSecret() {
		return appSecret;
	}

	public void setAppSecret(String appSecret) {
		this.appSecret = appSecret;
	}

}
